package com.ruoyi.api.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DzHuodong;
import com.ruoyi.system.service.IDzHuodongService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 热门活动Controller
 * 
 * @author ruoyi
 * @date 2023-09-07
 */
@RestController
@RequestMapping("/api/huodong")
public class DzHuodongApiController extends BaseController
{
    @Autowired
    private IDzHuodongService dzHuodongService;

    /**
     * 查询热门活动列表
     */
    @GetMapping("/list")
    public TableDataInfo list(DzHuodong dzHuodong)
    {
        startPage();
        List<DzHuodong> list = dzHuodongService.selectDzHuodongListWeb(dzHuodong);
        return getDataTable(list);
    }

    /**
     * 导出热门活动列表
     */
    @Log(title = "热门活动", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DzHuodong dzHuodong)
    {
        List<DzHuodong> list = dzHuodongService.selectDzHuodongListWeb(dzHuodong);
        ExcelUtil<DzHuodong> util = new ExcelUtil<DzHuodong>(DzHuodong.class);
        util.exportExcel(response, list, "热门活动数据");
    }

    /**
     * 获取热门活动详细信息
     */
    @GetMapping(value = "/{hdId}")
    public AjaxResult getInfo(@PathVariable("hdId") Long hdId)
    {
        return AjaxResult.success(dzHuodongService.selectDzHuodongByHdId(hdId));
    }

    /**
     * 新增热门活动
     */
    @Log(title = "热门活动", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DzHuodong dzHuodong)
    {
        return toAjax(dzHuodongService.insertDzHuodong(dzHuodong));
    }

    /**
     * 修改热门活动
     */
    @Log(title = "热门活动", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DzHuodong dzHuodong)
    {
        return toAjax(dzHuodongService.updateDzHuodong(dzHuodong));
    }

    /**
     * 删除热门活动
     */
    @Log(title = "热门活动", businessType = BusinessType.DELETE)
	@DeleteMapping("/{hdIds}")
    public AjaxResult remove(@PathVariable Long[] hdIds)
    {
        return toAjax(dzHuodongService.deleteDzHuodongByHdIds(hdIds));
    }
}
